home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The 640 MEG Shareware Studio 2
/
The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO
/
basic
/
iqb9107.zip
/
QTEST.BAS
< prev
next >
Wrap
BASIC Source File
|
1991-06-27
|
2KB
|
68 lines
' QTest.Bas
' QTest - Test the timer library. This program
' times how long it takes to obtain the current
' time with the two methods described in the
' article
DECLARE SUB PrintResults (A AS LONG, B AS LONG, S1 AS STRING, S2 AS STRING)
DECLARE FUNCTION tStart& ()
DECLARE FUNCTION tFormat$ (T1 AS LONG, T2 AS LONG)
DECLARE FUNCTION tDiff! (StartTime AS LONG, EndTime AS LONG)
DECLARE FUNCTION tGet& ()
DECLARE SUB GetTime (H AS INTEGER, M AS INTEGER, S AS INTEGER, S100 AS INTEGER)
DIM SHARED EmptyLoopTime AS SINGLE
DIM Q AS LONG
DIM T1 AS LONG, T2 AS LONG, I AS LONG, J AS LONG
DIM Hour AS INTEGER, Minute AS INTEGER
DIM Second AS INTEGER, Sec100 AS INTEGER
T1 = tStart&
FOR I = 1 TO 1000000
NEXT I
T2 = tGet&
CALL PrintResults(T1, T2, "*** Empty Loop ***", "Loop.")
EmptyLoopTime = tDiff(T1, T2)
T1 = tStart&
FOR I = 1 TO 1000000
X = TIMER
NEXT I
T2 = tGet&
CALL PrintResults(T1, T2, "*** QB TIMER ***", "function call.")
T1 = tStart&
FOR I = 1 TO 1000000
CALL GetTime(Hour, Minute, Second, Sec100)
NEXT I
T2 = tGet&
CALL PrintResults(T1, T2, "*** GetTime ***", "subprogram call.")
T1 = tStart&
FOR I = 1 TO 1000000
Q = tGet&
NEXT I
T2 = tGet&
CALL PrintResults(T1, T2, "*** tGet& ***", "function call.")
PRINT "Tests completed."
END
SUB PrintResults (A AS LONG, B AS LONG, S1 AS STRING, S2 AS STRING)
' PrintResults displays an accurate message only if you run the
' test loop 1,000,000 times
DIM tInterval AS SINGLE
PRINT tFormat$(A, B);
PRINT " seconds for 1,000,000 invocations of "; S1
tInterval = tDiff!(A, B) - EmptyLoopTime
' Adjust display for midnight crossover.
' 60 * 60 * 24 is the number of seconds in a day/
IF tInterval < 0 THEN
tInterval = tInterval + (60! * 60! * 24!)
END IF
PRINT "This equals ";
PRINT USING "########.######"; tInterval;
PRINT " microseconds per "; S2
END SUB